#!/usr/bin/env python3
# -*- coding: utf-8 -*-


def t1():
    n = 0

    def t2():
        nonlocal n  # 修改上层的n值
        x = n  # 重新赋值x
        n += 1  # 每次执行函数+1
        return x  # 返回修改之后的值

    return t2  # 返回x


c = t1()
print(c())  # 0
print(c())  # 1
print(c())  # 2
print(c())  # 3
print(c.__closure__[0].cell_contents)